home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / VGATUT2.ZIP / VGACIRCL.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-06  |  4.1 KB  |  153 lines

  1. //-----------------------------------------------
  2. // VGA Circles - A program to demonstrate drawing
  3. //         circles.  Barny Mercer  - 3/8/95
  4. //-----------------------------------------------
  5.  
  6. #include "vgafunc.h"
  7. #include <conio.h>
  8. #include <stdlib.h>
  9. #include <stdio.h>
  10. #include <sys/timeb.h>
  11.  
  12. void SmallPoorCircle( void );
  13. void SmallImprCircle( void );
  14. void PoorCocen( void );
  15. void ImprCocen( void );
  16. void PoorRandCirc( void );
  17. void ImprRandCirc( void );
  18.  
  19. void Intro(void);
  20. void Outro(void);
  21.  
  22. void main(void)
  23. {
  24.     int Tmp=0;
  25.  
  26.     Intro();
  27.  
  28.     // VGA mode
  29.     VidMode(VID_320x200);
  30.  
  31.     // draw small circles to display accuracy
  32.     SmallPoorCircle();
  33.     SmallImprCircle();
  34.  
  35.     // draw cocentric circles to demonstrate speed and accuracy
  36.     PoorCocen();
  37.     ImprCocen();
  38.  
  39.     // draw random circles because I've done this with everything else <grin>
  40.     PoorRandCirc();
  41.     ImprRandCirc();
  42.  
  43.     // return us to text mode
  44.     VidMode(VID_TEXT);
  45.  
  46.     Outro();
  47.  
  48. }
  49. //-----------------------------------------------------------
  50. void SmallPoorCircle(void)
  51. {
  52.     printf( "Small circle - Poor algortihm" );
  53.     DrawCircle( 160, 100, 2, 15);
  54.  
  55.     getch();
  56.     VidMode(VID_320x200);   // clear screen and reset text position
  57. }
  58. //-----------------------------------------------------------
  59. void SmallImprCircle(void)
  60. {
  61.     printf( "Small circle - Improved algorithm" );
  62.     ImpDrawCircle( 160, 100, 2, 15);
  63.  
  64.     getch();
  65.     VidMode(VID_320x200);   // clear screen and reset text position
  66. }
  67. //-----------------------------------------------------------
  68. void PoorCocen(void)
  69. {
  70.     printf( "Cocentric circles - Poor algorithm" );
  71.  
  72.     for (int Tmp=1; Tmp<100; Tmp += 3)
  73.     DrawCircle( 160, 100, Tmp, Tmp );
  74.  
  75.     getch();
  76.  
  77.     VidMode(VID_320x200);
  78. }
  79. //-----------------------------------------------------------
  80. void ImprCocen(void)
  81. {
  82.     printf( "Cocentric circles - Improved algorithm" );
  83.  
  84.     for (int Tmp=1; Tmp<100; Tmp += 3)
  85.     ImpDrawCircle( 160, 100, Tmp, Tmp );
  86.  
  87.     getch();
  88.  
  89.     VidMode(VID_320x200);
  90. }
  91. //-----------------------------------------------------------
  92. void PoorRandCirc(void)
  93. {
  94.     printf( "Yet another random routine...... hehe" );
  95.  
  96.     getch();
  97.  
  98.     for (int Tmp=0; Tmp<100; Tmp++)
  99.     DrawCircle( (rand()%320), (rand()%200), (rand()%100), (rand()%256) );
  100.  
  101.     getch();
  102.  
  103.     VidMode(VID_320x200);
  104. }
  105. //-----------------------------------------------------------
  106. void ImprRandCirc(void)
  107. {
  108.     printf( "Surprised?  <grin>" );
  109.  
  110.     getch();
  111.  
  112.     for (int Tmp=0; Tmp<100; Tmp++)
  113.     ImpDrawCircle( (rand()%320), (rand()%200), (rand()%100), (rand()%256) );
  114.  
  115.     getch();
  116.  
  117.     VidMode(VID_320x200);
  118. }
  119. //-----------------------------------------------------------
  120. void Intro(void)
  121. {
  122.     VidMode( VID_TEXT );    // make sure that we are in text mode
  123.  
  124.     printf( "Hi there & welcome to the second part of this VGA tutorial.\n\n" );
  125.     printf( "This program concerns it's self with circles and looks at two functions\n");
  126.     printf( "for drawing them....\n\n");
  127.     printf( "1.   This routine is slow & inacurate but forms the basis of the second\n" );
  128.     printf( "     routine.\n");
  129.     printf( "2.   Much better.  Faster & more accurate.\n\n" );
  130.     printf( "Take a look....." );
  131.  
  132.     getch();
  133.  
  134.     // clear screen by re-selecting text mode
  135.     VidMode(VID_TEXT);
  136. }
  137. //-----------------------------------------------------------
  138. void Outro(void)
  139. {
  140.     printf( "Good.  Now we have a semi-decent circle routine to add to our library.\n\n");
  141.     printf( "I hope you've enjoyed this tutorial and that you'll find it useful.\n\n");
  142.     printf( "Many thanks to Richard Griffiths who's been porting this code to Pascal\n");
  143.     printf( "for me.\nAs yet, this tutorial is still not available by FTP but I'm working\n");
  144.     printf( "on it.\n\nBye for now......  \n\n" );
  145.     printf( "Barny Mercer      : barny.mercer@zetnet.co.uk \n" );
  146.     printf( "                  : http://www.zetnet.co.uk/users/bmercer/ \n\n");
  147.     printf( "Richard Griffiths : richard.griffiths@zetnet.co.uk \n" );
  148.     printf( "                  : http://www.zetnet.co.uk/users/rgriff/\n");
  149.  
  150.     getch();
  151.  
  152. }
  153.